package com.lysj.bhp.financial.controller;

import com.lysj.bhp.financial.base.FinancialContent;
import com.lysj.bhp.financial.domain.UserFinancialRecord;
import com.lysj.bhp.user.domain.User;
import com.lysj.bhp.util.web.ParamUtil;
import com.lysj.bhp.util.web.Resp;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author zk
 * @description
 * @create 2018-07-20 16:50
 **/
@RestController
@RequestMapping("admin/user_financial_record")
public class UserFinancialRecordController extends FinancialContent {

    @GetMapping("/show_financail_user")
    public Resp list(Long financialId) {
        return new Resp(userFinancialRecordRepository.findByFinancialId(financialId));
    }

    @PostMapping("/remove")
    public Resp remove(UserFinancialRecord model) {
        userFinancialRecordRepository.delete(model.getUserFinancialRecordId());
        return new Resp("删除成功");
    }

    @PostMapping("/add")
    public Resp add(UserFinancialRecord model){
        if(ParamUtil.isBlack(model.getUserId())){
            return  new Resp("请选择用户");
        }
        User user = userRepository.findOne(model.getUserId());
        if(user == null){
            return new Resp("用户不存在");
        }
        model.setEmail(user.getEmail());
        if(ParamUtil.isBlack(model.getInvestmentPortion())){
            return  new Resp("请输入投资份额");
        }
        if(ParamUtil.isBlack(model.getDivide())){
            return  new Resp("请输入利息数量");
        }
        model.setInvestmentDate(new Date());
        return new Resp("添加成功");
    }
}
